package docs

import (
	"io/ioutil"
	"os"
	"strings"
)


type FormattingGenerator struct {
	DocsPath string
}

func (f *FormattingGenerator) Format() error {
	// 格式化md文件中图片的位置由绝对路径变为相对路径
	Source := "\\"
	target := "/"
	publicPath := "D:\\个人项目\\github\\muxicode.github.io\\docs\\.vuepress\\public"
	empty := ""
	bs, err := os.ReadFile(f.DocsPath)
	if err != nil {
		return err
	}
	// write to file
	n1 := strings.Replace(string(bs), publicPath, empty, -1)
	n2 := strings.Replace(n1, Source, target, -1)
	err = ioutil.WriteFile(f.DocsPath, []byte(n2), 0644)
	return err
}
